package com.naiterui.ehp.bs.search.config;

import lombok.extern.slf4j.Slf4j;

/**
 * <pre>
 *    ES集群配置
 * </pre>
 *
 * @author 王泽浩
 * @date 2018/9/2 下午3:56
 * @since 1.0.0
 */
@Slf4j
public class EsProperties {

    public static final String SPLIT_NODES = ";";

    /**
     * 集群名称
     */
    private String clusterName;

    /**
     * 集群副本数
     */
    private Integer replicasNum;

    /**
     * 链接时长
     */
    private Integer keepAlive;

    /**
     * 节点列表
     */
    private String nodes;

    public void init() {
        String[] nodes = this.getNodes().split(EsProperties.SPLIT_NODES);
        if (this.getReplicasNum() == null) {
            int replicasNum = nodes.length - 1;
            this.setReplicasNum(replicasNum);
            log.info("初始化 EsProperties 未指定副本数，设置默认副本数(节点数-1) replicasNum: {}", replicasNum);
        } else {
            log.info("初始化 EsProperties 设置副本数 replicasNum: {}", this.getReplicasNum());
        }
    }

    public String getClusterName() {
        return clusterName;
    }

    public void setClusterName(String clusterName) {
        this.clusterName = clusterName;
    }

    public Integer getReplicasNum() {
        return replicasNum;
    }

    public void setReplicasNum(Integer replicasNum) {
        this.replicasNum = replicasNum;
    }

    public String getNodes() {
        return nodes;
    }

    public void setNodes(String nodes) {
        this.nodes = nodes;
    }

    public Integer getKeepAlive() {
        return keepAlive;
    }

    public void setKeepAlive(Integer keepAlive) {
        this.keepAlive = keepAlive;
    }
}
